#include "aboutdialog.h"
#include "ui_aboutdialog.h"

AboutDialog::AboutDialog(QWidget *parent) :
   QDialog(parent),
   ui(new Ui::AboutDialog)
{
   ui->setupUi(this);
   loaded = false;
}

AboutDialog::~AboutDialog()
{
   delete ui;
}

void AboutDialog::showEvent(QShowEvent *)
{
   if (loaded) return;
   ui->versionNumber->setText(Utils::versionNumber());

   ui->homepage->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
   ui->homepage->setOpenExternalLinks(true);
   ui->homepage->setText("<a href=\"http://yasai.codeplex.com\">Yasai website: yasai.codeplex.com</a>");

   ui->authorEmail->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
   ui->authorEmail->setOpenExternalLinks(true);
   ui->authorEmail->setText("<a href=\"mailto:julian.wong@live.com\">E-mail: julian.wong@live.com</a>");

   ui->linkQt->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
   ui->linkQt->setOpenExternalLinks(true);
   ui->linkQt->setText("<a href=\"http://qt-project.org\">Qt 5.0.2: qt-project.org</a>");

   ui->linkLib7zip->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
   ui->linkLib7zip->setOpenExternalLinks(true);
   ui->linkLib7zip->setText("<a href=\"https://code.google.com/p/lib7zip/\">lib7zip 1.6.4: code.google.com</a>");

   ui->linkIcon->setTextInteractionFlags(Qt::LinksAccessibleByMouse);
   ui->linkIcon->setOpenExternalLinks(true);
   ui->linkIcon->setText("<a href=\"http://somerandomdude.com/work/iconic/\">Iconic: somerandomdude.com</a>");
   loaded = true;
}

void AboutDialog::on_aboutTabWidget_currentChanged(int index)
{
   if (!ui->licenseEdit->document()->isEmpty()) return;
   if (index != ui->aboutTabWidget->indexOf(ui->licenseTab)) return;
   QFile f(":/license/res/license/license.txt");
   f.open(QFile::ReadOnly | QFile::Text);
   QTextStream in(&f);
   ui->licenseEdit->setPlainText(in.readAll());
   f.close();
}
